/**
 * @author Simon Richardson - simon@ustwo.co.uk
 */
package org.osflash.signals;

import asunit.asserts.AssertEquals;
import asunit.asserts.AssertEqualsArrays;
import asunit.framework.IAsync;

class MonoSignalDispatchVarArgsTest {

	@:meta(Inject())
	public var async : IAsync;
	public var completed : MonoSignal;
	@:meta(Before())
	public function setUp() : Void {
		completed = new MonoSignal(int, int, int, int);
	}

	@:meta(After())
	public function tearDown() : Void {
		completed.removeAll();
		completed = null;
	}

	//////
	@:meta(Test())
	public function adding_vararg_at_0_should_not_throw_error() : Void {
		completed.add(handlerArgsAt0());
	}

	//////
	@:meta(Test())
	public function adding_vararg_at_1_should_not_throw_error() : Void {
		completed.add(handlerArgsAt1());
	}

	//////
	@:meta(Test())
	public function adding_vararg_at_2_should_not_throw_error() : Void {
		completed.add(handlerArgsAt2());
	}

	//////
	@:meta(Test())
	public function adding_vararg_at_0_then_dispatch_should_not_throw_error() : Void {
		completed.add(handlerArgsAt0());
		completed.dispatch(0, 1, 2, 3);
	}

	//////
	@:meta(Test())
	public function adding_vararg_at_1_then_dispatch_should_not_throw_error() : Void {
		completed.add(handlerArgsAt1());
		completed.dispatch(0, 1, 2, 3);
	}

	//////
	@:meta(Test())
	public function adding_vararg_at_2_then_dispatch_should_not_throw_error() : Void {
		completed.add(handlerArgsAt2());
		completed.dispatch(0, 1, 2, 3);
	}

	//////
	@:meta(Test())
	public function verify_num_args_after_dispatch() : Void {
		completed.add(verifyNumArgs);
		completed.dispatch(0, 1, 2, 3);
	}

	function handlerArgsAt0() : Dynamic {
		return function() : Void {
			assertEqualsArrays("Arguments should be [0,1,2,3]", [0, 1, 2, 3], args);
			assertEquals("Number of var arguments should be 4", 4, args.length);
		}
;
	}

	function handlerArgsAt1() : Dynamic {
		return function(a : Int) : Void {
			assertEqualsArrays("Arguments should be [1,2,3]", [1, 2, 3], args);
			assertEquals("Number of var arguments should be 3", 3, args.length);
		}
;
	}

	function handlerArgsAt2() : Dynamic {
		return function(a : Int, b : Int) : Void {
			assertEqualsArrays("Arguments should be [2,3]", [2, 3], args);
			assertEquals("Number of var arguments should be 2", 2, args.length);
		}
;
	}

	function verifyNumArgs() : Void {
		assertEquals("Number of arguments should be 4", 4, args.length);
	}

}

